home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F25223_DrawingCanvas.java < prev    next >
Encoding:
Java Source  |  2000-11-10  |  41.9 KB  |  1,164 lines

  1. /**
  2.     ----------------------------------------------------------------------------------------
  3.     International Microcomputer Software Inc. @1997 -- Rob Mayfield
  4.     This class does the work of using the IMSI SDK. It connects the application to
  5.     the application server (inproc or local), loads drawings and provides the
  6.     ability to draw with the mouse on the screen.
  7.     Note: It appears to be to early to use get the Drawings container:
  8.      m_IDrawings = (imsigx40.Drawings) m_IApp.getDrawings(); in the constructor of this
  9.     class
  10.  
  11.     NOTE: import imsigx40.*; Although it we be nice to import the TypeLib interface
  12.     constructed by the Microsoft Type Library Wizard, some of the interface
  13.     names conflict with Java names (ie. Graphics) so we must import them by
  14.     full Java pathing (ie. imsigx40.Graphics or imsigx40.IApplication).
  15.  
  16.     Note: Also Microsoft requires that you use an interface to access an OLE object, not
  17.     the class. ie. m_IApp = (imsigx40.IApplication) new imsigx40.XApplication(). Here
  18.     XApplication is a class and must be casted to the IApplication (an interface) to be used.
  19.     Therefore use only those objects identified by an interface not a class.
  20.     ----------------------------------------------------------------------------------------
  21. **/
  22.  
  23. import java.awt.*;
  24. import java.util.*;
  25. import java.awt.peer.*;
  26. import PropObject;
  27. //import java.awt.peer.ComponentPeer;     // needed to ge the peer
  28. import com.ms.awt.peer.*;  // Microsoft specific peer to get the windows handle.
  29.  
  30. class DrawingCanvas extends java.awt.Canvas
  31. {
  32.  
  33.     SDKDemo Parent;
  34.  
  35.     //  IMSI Application  COM Interface variable
  36.     public imsigx40.IApplication m_IApp=null;
  37.  
  38.     // these com interfaces are used for drawings
  39.     public imsigx40.Drawings m_IDrawings=null;
  40.     public imsigx40.IDrawing m_ITheDrawing=null;
  41.  
  42.     // these com interfaces are used for Views
  43.     public imsigx40.Views m_IViews=null;
  44.     public imsigx40.View m_ITheView=null;
  45.  
  46.     // these com interfaces are used for Graphics
  47.     public imsigx40.Graphics m_IGraphics=null;
  48.     public imsigx40.IGraphic m_ITheGraphic=null;
  49.     public imsigx40.IGraphic m_ISelectedGraphic=null;
  50.  
  51.     // these com interfaces are used for Vertices (splines points)
  52.     public imsigx40.Vertices m_IVertices=null;
  53.     public imsigx40.IVertex m_ITheVertex=null;
  54.  
  55.     private double screenHeight=0.0, screenWidth=0.0, screenLeft=0.0, screenTop=0.0;
  56.  
  57.     private double prevX=0.0, prevY=0.0;
  58.     private double pprevX=0.0, pprevY=0.0;
  59.     private double currX=0.0, currY=0.0;
  60.     private int savedColor = 0x000000;  // default to black
  61.  
  62.     private double viewHeight=0.0, viewWidth=0.0, viewLeft=0.0, viewTop=0.0;
  63.     protected boolean Zoom = false;
  64.     protected boolean draggingStarted = false;
  65.     protected boolean splineStarted = false;
  66.     protected double xStart = 0.0, yStart = 0.0;
  67.     protected double ScrollCenterX, ScrollCenterY; // Dead center for scrolling
  68.     protected double ScrollRangeX, ScrollRangeY; // Scroll range
  69.  
  70.     protected int whichButtonDown = 0;
  71.     protected boolean fromNew = false;
  72.     protected boolean ClipIt = false;
  73.  
  74.  
  75.     /** constructs the class setting the parent for reference capabitity */
  76.     public DrawingCanvas(SDKDemo parent)
  77.     {   super ();
  78.         Parent = parent;
  79.  
  80.         /*
  81.            This is where we construct the OLE Variable and connect
  82.            the application to the server.
  83.          */
  84.         try
  85.         {   // first connect to application server. imsigx40.XApplication must
  86.             // be used to connect to the inproc_server IMSIGX40.DLL. If you
  87.             // wish to connect to the local server TC40.exe use imsigx40.Application
  88.             if (m_IApp==null)
  89.                 m_IApp = (imsigx40.IApplication) new imsigx40.XApplication();
  90.         }
  91.         catch (com.ms.com.ComException e)
  92.         {   Parent.StatusBox.setText("System Error connecting to IMSIGX40 OLE");
  93.         }
  94.         catch (Exception e)
  95.         {   Parent.StatusBox.setText("Error connecting to IMSIGX40 OLE");
  96.         }
  97.  
  98.     }
  99.  
  100.     /** NewDrawing sets up a standard default drawing on the screen. It sets the
  101.         screen size to that of the canvas.
  102.      **/
  103.     public void NewDrawing()
  104.     {
  105.         Rectangle Rec = this.bounds();  // drawing surface rectangle
  106.         String m_fileName;
  107.  
  108.         try   // all results for COM/OLE come as exceptions so we must set up handling
  109.         {
  110.             // Create a Variant for an optional parameter
  111.             com.ms.com.Variant nParam = new com.ms.com.Variant();
  112.             // Set the Variant for no parameter
  113.             nParam.noParam();
  114.  
  115.             if (m_IApp==null)  // we should have connected already but just in case
  116.             {
  117.  
  118.                 m_IApp = (imsigx40.IApplication) new imsigx40.XApplication();
  119.                 m_IDrawings = null;
  120.             }
  121.  
  122.             if (m_IDrawings==null)
  123.             {   // either from reset or first time through, set Drawings container
  124.                 // for some reason trying to set this in init() fails.
  125.                 m_IDrawings = (imsigx40.Drawings) m_IApp.getDrawings();
  126.             }
  127.  
  128.             // remove previous instance
  129.             if (m_ITheDrawing != null)
  130.                 m_ITheDrawing.Close(nParam, nParam, nParam);
  131.  
  132.             //m_IDrawings = null;
  133.             m_ITheDrawing = null;
  134.             m_IViews = null;
  135.             m_ITheView = null;
  136.  
  137.             // method -- imsigx40.IDrawing Open(java.lang.String, com.ms.com.Variant [optional], com.ms.com.Variant [optional]);
  138.              m_ITheDrawing = (imsigx40.IDrawing) m_IDrawings.Add(nParam);
  139.  
  140.             // display the name of the drawing. Also this is returned by the SDK so is
  141.             // a good check that it loaded
  142.             String str =  m_ITheDrawing.getName();
  143.             Parent.StatusBox.setText("str: " + str);
  144.  
  145.             // we now get the views collection for this drawing
  146.             // method -- imsigx40.Views getViews();
  147.  
  148.             m_IViews = (imsigx40.Views) m_ITheDrawing.getViews();
  149.  
  150.             // add a new view to the views collection for drawing
  151.             // Class Method -- imsigx40.View Add(com.ms.com.Variant [optional], com.ms.com.Variant [optional]);
  152.               m_ITheView = (imsigx40.View) m_IViews.Add(nParam, nParam);
  153.  
  154.             // now that we have the particular view for the drawing, call the our
  155.             // repaint procedure to handle the painting using the SDK, we set
  156.             // the new global coordinates to accomplish the painting
  157.  
  158.             screenWidth = Rec.width;
  159.             screenHeight = Rec.height;
  160.             screenLeft = 0.0;
  161.             screenTop = 0.0;
  162.  
  163.             viewWidth = 0.0;
  164.             viewHeight = 0.0;
  165.             viewLeft = 0.0;
  166.             viewTop = 0.0;
  167.             viewZoomBy(0.0);
  168.             Zoom = false;
  169.             //repaint();  // calls this classes paint(), which does the drawing local and via SDK
  170.  
  171.             nParam.VariantClear();  // clear the Variant
  172.             fromNew = true;  // not a new drawing
  173.  
  174.             m_ISelectedGraphic = null;
  175.  
  176.         }
  177.         catch (com.ms.com.ComException e)
  178.         {   Parent.StatusBox.setText("Error connecting to IMSIGX40 OLE");
  179.         }
  180.         catch (Exception e)
  181.         {
  182.             Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  183.         }
  184.  
  185.     }
  186.  
  187.     /** OpenDrawing pops up the OpenDialog dialog box and allow for a choice of files
  188.         to display on the screen. If a file is choosen, the filename is passed
  189.         to the SDK where it is loaded and drawn on the canvas.
  190.      **/
  191.     public String OpenDrawing(String fName)
  192.     {
  193.         Rectangle Rec = this.bounds();  // drawing surface rectangle
  194.         String m_fileName;
  195.  
  196.         if (fName == null)
  197.         {
  198.             // use the Java file open dialog to get and choose available files
  199.             FileDialog openFileDialog = new java.awt.FileDialog(Parent.frame, "Open Drawing File", FileDialog.LOAD);
  200.             openFileDialog.setFile ("*.tcw");
  201.  
  202.             openFileDialog.show();
  203.             m_fileName = openFileDialog.getFile();
  204.         }
  205.         else
  206.             m_fileName = fName;  // filename passed as method param
  207.  
  208.         if (m_fileName != null && m_fileName.indexOf(".tcw") > -1)  // load only valid .tcw files
  209.         {
  210.  
  211.             try   // all results for COM/OLE come as exceptions so we must set up handling
  212.             {
  213.                 // set cursor to wait hourglass
  214.                 int currentCursor = Parent.frame.getCursorType();
  215.                 Parent.frame.setCursor(Frame.WAIT_CURSOR);
  216.  
  217.                 // Create a Variant for an optional parameter
  218.                 com.ms.com.Variant nParam = new com.ms.com.Variant();
  219.                 // Set the Variant for no parameter
  220.                 nParam.noParam();
  221.  
  222.                 if (m_IApp==null)  // we should have connected already but just in case
  223.                 {
  224.  
  225.                     m_IApp = (imsigx40.IApplication) new imsigx40.XApplication();
  226.                     m_IDrawings = null;
  227.                 }
  228.  
  229.                 if (m_IDrawings==null)
  230.                 {   // either from reset or first time through, set Drawings container
  231.                     // for some reason trying to set this in init() fails.
  232.                     m_IDrawings = (imsigx40.Drawings) m_IApp.getDrawings();
  233.                 }
  234.  
  235.                 // remove previous instance
  236.                 if (m_ITheDrawing != null)
  237.                     m_ITheDrawing.Close(nParam, nParam, nParam);
  238.  
  239.                 //m_IDrawings = null;
  240.                 m_ITheDrawing = null;
  241.                 m_IViews = null;
  242.                 m_ITheView = null;
  243.  
  244.                 // method -- imsigx40.IDrawing Open(java.lang.String, com.ms.com.Variant [optional], com.ms.com.Variant [optional]);
  245.                  m_ITheDrawing = (imsigx40.IDrawing) m_IDrawings.Open(m_fileName, nParam, nParam);
  246.  
  247.                 // display the name of the drawing. Also this is returned by the SDK so is
  248.                 // a good check that it loaded
  249.                 String str =  m_ITheDrawing.getName();
  250.                 Parent.StatusBox.setText("str: " + str);
  251.  
  252.                 // we now get the views collection for this drawing
  253.                 // method -- imsigx40.Views getViews();
  254.  
  255.                 m_IViews = (imsigx40.Views) m_ITheDrawing.getViews();
  256.  
  257.                 // add a new view to the views collection for drawing
  258.                 // Class Method -- imsigx40.View Add(com.ms.com.Variant [optional], com.ms.com.Variant [optional]);
  259.                   m_ITheView = (imsigx40.View) m_IViews.Add(nParam, nParam);
  260.  
  261.                 // now that we have the particular view for the drawing, call the Java
  262.                 // repaint method to handle the painting using the SDK, we set
  263.                 // the new global coordinates to 0's to accomplish the painting
  264.                 viewWidth = 0.0;
  265.                 viewHeight = 0.0;
  266.                 viewLeft = 0.0;
  267.                 viewTop = 0.0;
  268.                 viewZoomBy(0.0);   // Specifying 0.0 as the zoom factor redraws...
  269.                 Zoom = true;
  270.  
  271.                 //repaint();  // calls this classes paint(), which does the drawing local and via SDK
  272.                 // reset cursor to wait normal
  273.                 Parent.frame.setCursor(currentCursor);
  274.  
  275.                 nParam.VariantClear();  // clear the Variant
  276.                 fromNew = true;  // not a new drawing
  277.  
  278.                 m_ISelectedGraphic = null;
  279.                 return m_fileName;
  280.             }
  281.             catch (com.ms.com.ComFailException e)  // catch failure exception
  282.             {   Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  283.                 return "Error in opening: " + m_fileName;
  284.             }
  285.             catch (com.ms.com.ComException e) // catch system failure exception
  286.             {   Parent.StatusBox.setText("System Error in OLE transaction (IMSIGX40)");
  287.                 return "Error in opening: " + m_fileName;
  288.             }
  289.             catch (Exception e)  // catch the rest of the errors
  290.             {
  291.                 Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  292.                 return "Error in opening: " + m_fileName;
  293.             }
  294.  
  295.         }
  296.         else return null;
  297.  
  298.     }
  299.  
  300.     public void displayProperties()
  301.     {   if (m_ITheDrawing != null)
  302.         {
  303.             viewPropertiesDialog viewProp = null;
  304.         
  305.             //public abstract imsigx40.Properties getProperties();
  306.             imsigx40.Properties m_IProperties = (imsigx40.Properties) m_ITheDrawing.getProperties();
  307.             int count = m_IProperties.getCount();
  308.             com.ms.com.Variant varI = new com.ms.com.Variant();
  309.             com.ms.com.Variant varValue = new com.ms.com.Variant();
  310.             String pTypeStr = null;
  311.             String pArrayStr = null;
  312.             String pValueStr = null;
  313.             short pType;
  314.             String pName = null;
  315.             int nLen=0, tLen=0, vLen=0;
  316.             Vector vecList = new Vector();
  317.             
  318.             for (int ii=0; ii < count-1; ii++)
  319.             {   
  320.                 // METHOD: public abstract imsigx40.Property getItem(com.ms.com.Variant);                
  321.                   varI.putInt(ii);
  322.                 imsigx40.Property m_IItem = (imsigx40.Property) m_IProperties.getItem(varI);
  323.                 pName = m_IItem.getName();
  324.                 pType = m_IItem.getType();
  325.                 // METHOD: public abstract com.ms.com.Variant getValue(int);
  326.                 pValueStr = m_IItem.getValue(0).toString();
  327.                 // check if it is an array by ANDing with VariantArray which produces type of array
  328.                 if ((pType & com.ms.com.Variant.VariantArray) != 0)
  329.                 {
  330.                     pType &= ~com.ms.com.Variant.VariantArray;
  331.                     pArrayStr = "Array of ";
  332.                 }
  333.                 else
  334.                     pArrayStr = "";
  335.  
  336.                 switch (pType)
  337.                 {   case com.ms.com.Variant.VariantShort:
  338.                          pTypeStr = "Short";
  339.                          break;
  340.                     case com.ms.com.Variant.VariantInt:
  341.                          pTypeStr = "Integer";
  342.                          break;
  343.                     case com.ms.com.Variant.VariantFloat:
  344.                          pTypeStr = "Float";
  345.                          break;
  346.                     case com.ms.com.Variant.VariantDouble:
  347.                          pTypeStr = "Double";
  348.                          break;
  349.                     case com.ms.com.Variant.VariantDate:
  350.                          pTypeStr = "Date";
  351.                          break;
  352.                     case com.ms.com.Variant.VariantString:
  353.                          pTypeStr = "String";
  354.                          break;
  355.                     case com.ms.com.Variant.VariantDispatch:
  356.                          pTypeStr = "Dispatch";
  357.                          break;
  358.                     case com.ms.com.Variant.VariantError:
  359.                          pTypeStr = "Error";
  360.                          break;
  361.                     case com.ms.com.Variant.VariantBoolean:
  362.                          pTypeStr = "Boolean";
  363.                          break;
  364.                     case com.ms.com.Variant.VariantVariant:
  365.                          pTypeStr = "Variant";
  366.                          break;
  367.                     case com.ms.com.Variant.VariantObject:
  368.                          pTypeStr = "Object";
  369.                          break;
  370.                     case com.ms.com.Variant.VariantByte:
  371.                          pTypeStr = "Byte";
  372.                          break;
  373.                     default: 
  374.                          pTypeStr = "Unknown";
  375.                          break;
  376.  
  377.                 }
  378.                 if (pName.length() > nLen) nLen = pName.length();
  379.                 if ((pArrayStr + pTypeStr).length() > tLen) tLen = (pArrayStr + pTypeStr).length();
  380.                 if (pValueStr.length() > vLen) vLen = pValueStr.length();
  381.                 vecList.addElement(new PropObject(pName, pArrayStr + pTypeStr, pValueStr));
  382.             }
  383.             //Dimension d = viewProp.size();
  384.             //viewProp.resize((nLen+tLen+vLen) * 10, d.height);
  385.             (viewProp = new viewPropertiesDialog(Parent.frame, false, vecList, nLen, tLen, vLen)).show();
  386.         }   
  387.  
  388.     }
  389.  
  390.  
  391.     public void setButtonDown(int b)
  392.     {   whichButtonDown = b;
  393.         splineStarted = false;  // reset so that spline stops drawing
  394.     }
  395.  
  396.  
  397.     // Zoom the drawing by 40 points in x and y directions
  398.     void ZoomPlus()
  399.     {
  400.         if (m_ITheDrawing != null)
  401.         {
  402.             viewZoomBy(1.414);
  403.         }
  404.     }
  405.  
  406.     // Zoom the drawing by 40 points in x and y directions
  407.     void ZoomMinus()
  408.     {
  409.         if (m_ITheDrawing != null)
  410.         {
  411.             viewZoomBy(0.707);
  412.         }
  413.  
  414.     }
  415.  
  416.     /* SCROLLING */
  417.  
  418.     // Verticle Scroll one line up
  419.     void VScrollLineUp()
  420.     {
  421.         if (m_ITheDrawing != null && m_ITheView != null)
  422.         {
  423.             double Y = viewTop - (viewHeight/2.0); // Center point of view.
  424.             double YOrig = Y;
  425.  
  426.             Y = Y + (viewHeight/32.0);  // scroll in the +Y direction
  427.             ViewScrollBy(0.0, Y - YOrig);
  428.         }
  429.     }
  430.  
  431.     // Verticle Scroll down one line
  432.     void VScrollLineDown()
  433.     {
  434.         if (m_ITheDrawing != null && m_ITheView != null)
  435.         {
  436.             double Y = viewTop - (viewHeight/2.0); // Center point of view.
  437.             double YOrig = Y;
  438.  
  439.             Y = Y - (viewHeight/32.0);  // scroll in the -Y direction
  440.             ViewScrollBy(0.0, Y - YOrig);
  441.         }
  442.  
  443.     }
  444.     // Verticle Scroll up one page
  445.     void VScrollPageUp()
  446.     {
  447.         if (m_ITheDrawing != null && m_ITheView != null)
  448.         {
  449.             double Y = viewTop - (viewHeight/2.0); // Center point of view.
  450.             double YOrig = Y;
  451.  
  452.             Y = Y + (viewHeight/8.0);  // scroll in the +Y direction
  453.             ViewScrollBy(0.0, Y - YOrig);
  454.         }
  455.     }
  456.     // Verticle Scroll down one page
  457.     void VScrollPageDown()
  458.     {
  459.         if (m_ITheDrawing != null && m_ITheView != null)
  460.         {
  461.             double Y = viewTop - (viewHeight/2.0); // Center point of view.
  462.             double YOrig = Y;
  463.             Y = Y - (viewHeight/8.0);  // scroll in the -Y direction
  464.             ViewScrollBy(0.0, Y - YOrig);
  465.         }
  466.     }
  467.  
  468.     // Horizontal Scroll on line up
  469.     void HScrollLineUp()
  470.     {
  471.         if (m_ITheDrawing != null && m_ITheView != null)
  472.         {
  473.             double X = viewLeft + (viewWidth/2.0); // Center point of view.
  474.             double XOrig = X;
  475.             X = X - (viewWidth/32.0);  // scroll in the -X direction
  476.             ViewScrollBy(X - XOrig, 0.0);
  477.         }
  478.     }
  479.     // Horizontal Scroll on line up
  480.     void HScrollLineDown()
  481.     {
  482.         if (m_ITheDrawing != null && m_ITheView != null)
  483.         {
  484.             double X = viewLeft + (viewWidth/2.0); // Center point of view.
  485.             double XOrig = X;
  486.             X = X + (viewWidth/32.0);  // scroll in the +X direction
  487.             ViewScrollBy(X - XOrig, 0.0);
  488.         }
  489.     }
  490.     // Horizontal Scroll on line up
  491.     void HScrollPageUp()
  492.     {
  493.         if (m_ITheDrawing != null && m_ITheView != null)
  494.         {
  495.             double X = viewLeft + (viewWidth/2.0); // Center point of view.
  496.             double XOrig = X;
  497.             X = X - (viewWidth/8.0);  // scroll in the -X direction
  498.             ViewScrollBy(X - XOrig, 0.0);
  499.         }
  500.     }
  501.     // Horizontal Scroll on line up
  502.     void HScrollPageDown()
  503.     {
  504.         if (m_ITheDrawing != null && m_ITheView != null)
  505.         {
  506.             double X = viewLeft + (viewWidth/2.0); // Center point of view.
  507.             double XOrig = X;
  508.             X = X + (viewWidth/8.0);  // scroll in the +X direction
  509.             ViewScrollBy(X - XOrig, 0.0);
  510.         }
  511.     }
  512.  
  513.  
  514.     void viewZoomBy(double Factor)
  515.     {
  516.  
  517.         boolean viewChanged;
  518.  
  519.         viewChanged = false;
  520.  
  521.         Rectangle rec = bounds();  // get full rectangle of graphics context
  522.  
  523.         try
  524.         {
  525.  
  526.             int CompHwnd = 0;
  527.             // get the Windows handle for the canvas so that IMSI's SDK can draw direct to the window
  528.             ComponentPeer p = this.getPeer();
  529.             if( p != null )
  530.             {
  531.                  ComponentPeerX peer1 = (ComponentPeerX)p;
  532.                  CompHwnd = peer1.gethwnd();  // Microsoft specific method
  533.             }
  534.  
  535.             byte b = 0;
  536.             m_ITheView.putUpdate(b);  // delay update until we tell it to
  537.             m_ITheView.putHWND(CompHwnd);
  538.             m_ITheView.putMappingMode(1);
  539.  
  540.             /* we don't want margins as this will redraw with margins.
  541.                Using the same screen coordinates this will shrink the screen
  542.                by margin each redraw.        
  543.             */
  544.             b = 0;
  545.             m_ITheView.putMargins(b);
  546.  
  547.             b = 1;  // set to same aspect ratio
  548.             m_ITheView.putFixedAspectRatio (b);
  549.  
  550.             boolean zoomIt = false;
  551.             // See if we need to start over.
  552.             if ((Factor <= 0.0) || ((viewWidth == 0.0) && (viewHeight == 0.0)))
  553.             {
  554.                // Factor <= 0.0 means reset.  Otherwise, initial settings.
  555.                 m_ITheView.putScreenLeft(0.0);
  556.                 m_ITheView.putScreenTop(0.0);
  557.                 m_ITheView.putScreenWidth(rec.width);
  558.                 m_ITheView.putScreenHeight(rec.height);
  559.  
  560.                 //m_ITheView.ZoomToExtents(); // zoom to the largest extents of the drawing.
  561.  
  562.                 viewLeft = m_ITheView.getViewLeft();
  563.                 viewTop = m_ITheView.getViewTop();
  564.                 viewWidth = m_ITheView.getViewWidth();
  565.                 viewHeight = m_ITheView.getViewHeight();
  566.                 screenLeft = m_ITheView.getScreenLeft();
  567.                 screenTop = m_ITheView.getScreenTop();
  568.                 screenWidth = m_ITheView.getScreenWidth();
  569.                 screenHeight = m_ITheView.getScreenHeight();        
  570.  
  571.                 zoomIt = true;
  572.                 viewChanged = true;
  573.             }
  574.  
  575.             if (Factor > 0.0 && Factor != 1.0)
  576.             {
  577.                // Keep the center fixed, and change view coordinates.
  578.                double vCenterX = viewLeft + (viewWidth/2.0);
  579.                double vCenterY = viewTop - (viewHeight/2.0);
  580.     
  581.                viewWidth = viewWidth / Factor;
  582.                viewHeight = viewHeight / Factor;
  583.                viewLeft = vCenterX - (viewWidth/2.0);
  584.                viewTop = vCenterY + (viewHeight/2.0);
  585.                viewChanged = true;
  586.             }
  587.  
  588.             // Synchronize the view to our new location and zoom.
  589.             m_ITheView.putViewLeft(viewLeft);
  590.             m_ITheView.putViewTop(viewTop);
  591.             m_ITheView.putViewWidth(viewWidth);
  592.             m_ITheView.putViewHeight(viewHeight);
  593.  
  594.             if (zoomIt)
  595.                 m_ITheView.ZoomToExtents(); // zoom to the largest extents of the drawing.
  596.  
  597.  
  598.             repaint(); // Update display.
  599.  
  600.             if (viewChanged) updateScrollParams(); // Keep scroll bars in sync.
  601.  
  602.         }
  603.         catch (Exception e)
  604.         {
  605.             Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  606.         }
  607.  
  608.     }
  609.  
  610.        void updateScrollParams()
  611.     {
  612.         if (m_ITheDrawing != null)
  613.         {
  614.  
  615.             double X1, Y1, X2, Y2;
  616.             double Delta1, Delta2;
  617.  
  618.             Parent.horizontalScrollbar.setValues(0, 1, 0, 32000);
  619.             Parent.horizontalScrollbar.setLineIncrement(320);
  620.             Parent.horizontalScrollbar.setPageIncrement(3200);
  621.  
  622.             Parent.verticalScrollbar.setValues(0, 1, 0, 32000);
  623.             Parent.verticalScrollbar.setLineIncrement(320);
  624.             Parent.verticalScrollbar.setPageIncrement(3200);
  625.  
  626.             // Arbitrary limits if all else fails.
  627.             ScrollCenterX = 0.0;
  628.             ScrollCenterY = 0.0;
  629.             ScrollRangeX = 1.0;
  630.             ScrollRangeY = 1.0;
  631.  
  632.             X1 = viewLeft;
  633.             Y1 = viewTop - viewHeight;
  634.             X2 = viewLeft + viewWidth;
  635.             Y2 = viewTop;
  636.             try
  637.             {
  638.  
  639.  
  640.                 // Set ScrollCenter to center of drawing's graphics.
  641.                 m_IGraphics = (imsigx40.Graphics) m_ITheDrawing.getGraphics();
  642.  
  643.  
  644.                 //TVarData(varDummy).VError = DISP_E_PARAMNOTFOUND;
  645.  
  646.                 // Create a Variant for an optional parameter
  647.                 com.ms.com.Variant varDummy = new com.ms.com.Variant();
  648.                 // Set the Variant for no parameter
  649.                 varDummy.noParam();
  650.  
  651.                 // Now we need to find the largest box surrounding our graphics
  652.                 // METHOD: public abstract imsigx40.BoundingBox CalcBoundingBox(com.ms.com.Variant);
  653.                 imsigx40.BoundingBox BBox = (imsigx40.BoundingBox) m_IGraphics.CalcBoundingBox(varDummy);
  654.  
  655.                 if (BBox.getEmpty() == 1) // true if bounding box empty
  656.                 {
  657.                     // METHOD: public abstract imsigx40.IVertex getMin();
  658.                     imsigx40.IVertex BoxMin = (imsigx40.IVertex) BBox.getMin();
  659.                     // METHOD: public abstract imsigx40.IVertex getMax();
  660.                     imsigx40.IVertex BoxMax = (imsigx40.IVertex) BBox.getMax();
  661.  
  662.                     // METHOD: public abstract double getX();
  663.                     X1 = BoxMin.getX();
  664.                     Y1 = BoxMin.getY();
  665.                     X2 = BoxMax.getX();
  666.                     Y2 = BoxMax.getY();
  667.  
  668.                     ScrollCenterX = (X1 + X2)/2.0;
  669.                     ScrollCenterY = (Y1 + Y2)/2.0;
  670.  
  671.                     // Set min and max for range to include current viewport.
  672.                     if (viewLeft < X1) X1 = viewLeft;
  673.                     if ((viewTop - viewHeight) < Y1) Y1 = viewTop - viewHeight;
  674.                     if ((viewLeft + viewWidth) > X2) X2 = viewLeft + viewWidth;
  675.                     if (viewTop > Y2) Y2 = viewTop;
  676.                 }
  677.             }
  678.             catch (Exception e)
  679.             {
  680.             }
  681.  
  682.             // Set ScrollRange based on largest area included.
  683.             Delta1 = ScrollCenterX - X1;
  684.             Delta2 = X2 - ScrollCenterX;
  685.             if (Delta1 > Delta2) ScrollRangeX = 2.0 * Delta1;
  686.             else ScrollRangeX = 2.0 * Delta2;
  687.  
  688.             Delta1 = ScrollCenterY - Y1;
  689.             Delta2 = Y2 - ScrollCenterY;
  690.             if (Delta1 > Delta2) ScrollRangeY = 2.0 *Delta1;
  691.             else ScrollRangeY = 2.0 * Delta2;
  692.  
  693.             ViewSetScrollPos();
  694.         }
  695.     }
  696.  
  697.     void ViewScrollBy(double DeltaX, double DeltaY)
  698.     {
  699.         viewLeft = viewLeft + DeltaX;
  700.         viewTop = viewTop + DeltaY;
  701.         viewZoomBy(1.0);
  702.     }
  703.  
  704.     void ViewSetScrollPos()
  705.     {
  706.         double VCenter;
  707.         int IMax;
  708.         double DMax, DPos, IPos;
  709.  
  710.         if (ScrollRangeX > 0.0)
  711.         {
  712.           IMax = Parent.horizontalScrollbar.getMaximum();
  713.           DMax = IMax;
  714.           VCenter = viewLeft + (viewWidth / 2.0);
  715.           DPos = (DMax / 2.0) + DMax * (VCenter - ScrollCenterX)/ScrollRangeX;
  716.  
  717.           if (DPos <= 0.0) IPos = 0;
  718.           else if (DPos >= DMax) IPos = IMax;
  719.           else IPos = DPos;  // round
  720.           Parent.horizontalScrollbar.setValue((int)IPos);
  721.         }
  722.  
  723.         if (ScrollRangeY > 0.0)
  724.         {
  725.           IMax = Parent.verticalScrollbar.getMaximum();
  726.           DMax = IMax;
  727.           VCenter = viewTop - (viewHeight / 2.0);
  728.           DPos = (DMax / 2.0) + DMax * (VCenter - ScrollCenterY)/ScrollRangeY;
  729.  
  730.           if (DPos < 0.0) IPos = 0;
  731.           else if (DPos > DMax) IPos = IMax;
  732.           else IPos = Math.round(DPos);
  733.           Parent.verticalScrollbar.setValue((int)IPos);
  734.  
  735.         }
  736.     }
  737.  
  738.  
  739.     public boolean mouseDrag (Event event, int x , int y)
  740.     {
  741.         //  mouse is being dragged accross canvas. This sets dragging to be true so that mouseUp
  742.         //  will know what to do with the mouse points.
  743.         if (m_ITheDrawing != null)
  744.         {
  745.             draggingStarted = true;
  746.             Parent.StatusBox.setText("mouse: " + x + "  " + y);
  747.         }
  748.         return true;
  749.     }
  750.  
  751.     public boolean mouseUp(Event  evt, int  x, int  y)
  752.     {
  753.  
  754.         //  mouse buton released. If dragging was started then assume this is finish of drag.
  755.         if (m_ITheDrawing != null && draggingStarted == true && m_ITheView != null)
  756.         {
  757.             if (whichButtonDown > 0)
  758.             {
  759.                 double[] daX = new double[1], daY = new double[1], daxStart = new double[1], dayStart = new double[1];
  760.                 //double[] daX = new int[1], daY = new int[1], daxStart = new int[1], dayStart = new int[1];
  761.                 daX[0] = daY[0] = 0.0;
  762.                 daxStart[0] = xStart;
  763.                 dayStart[0] = yStart;
  764.                 m_ITheView.ScreenToView(x, y, daX, daY);  // pass in a double and get double array returned
  765.                 m_ITheView.ScreenToView(xStart, yStart, daxStart, dayStart); // pass in a double and get double array returned
  766.                 switch (whichButtonDown)
  767.                 {    case Parent.CIRCLECLICK:
  768.                         draggingStarted = false;
  769.                         try  // always use the try/catch to catch any returned errors from OLE/SDK
  770.                         {
  771.                              m_IGraphics = (imsigx40.Graphics) m_ITheDrawing.getGraphics();
  772.                             m_ITheGraphic = m_IGraphics.AddCircleCenterAndPoint(daxStart[0], dayStart[0], 0, daX[0], daY[0], 0);
  773.                                byte b = 1;
  774.                             m_ITheView.putUpdate(b);  // delay update until we tell it to
  775.                             //m_ITheView.putHWND(CompHwnd);
  776.                             //m_ITheView.putMappingMode(1);
  777.                             m_IGraphics = null;
  778.                         }
  779.                         catch (Exception e)
  780.                         {
  781.                             Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  782.                         }
  783.                         break;
  784.                     case Parent.LINECLICK:
  785.                         try  // always use the try/catch to catch any returned errors from OLE/SDK
  786.                         {
  787.                              m_IGraphics = (imsigx40.Graphics) m_ITheDrawing.getGraphics();
  788.                             m_ITheGraphic = m_IGraphics.AddLineSingle(daxStart[0], dayStart[0], 0, daX[0], daY[0], 0);
  789.                             byte b = 1;
  790.                             m_ITheView.putUpdate(b);  // delay update until we tell it to
  791.                             //m_ITheView.putHWND(CompHwnd);
  792.                             //m_ITheView.putMappingMode(1);
  793.                             m_IGraphics = null;
  794.                         }
  795.                         catch (Exception e)
  796.                         {
  797.                             Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  798.                         }
  799.                         draggingStarted = false;
  800.                         break;
  801.  
  802.                     case Parent.SPLINECLICK:
  803.                         try  // always use the try/catch to catch any returned errors from OLE/SDK
  804.                         {
  805.                             // create a variant. Used as a placeholder to pass an OLE no parameter
  806.                             com.ms.com.Variant nParam = new com.ms.com.Variant();
  807.                             // Set the Variant for no parameter
  808.                             nParam.noParam();
  809.                             com.ms.com.Variant varX = new com.ms.com.Variant();
  810.                             com.ms.com.Variant varY = new com.ms.com.Variant();
  811.                             com.ms.com.Variant varZ = new com.ms.com.Variant();
  812.  
  813.                             if (!splineStarted)
  814.                             {
  815.  
  816.                                 varX.putDouble(daxStart[0]);
  817.                                 varY.putDouble(dayStart[0]);
  818.                                 varZ.putDouble(0.0);
  819.  
  820.                                 m_IGraphics = (imsigx40.Graphics) m_ITheDrawing.getGraphics();
  821.                                 m_ITheGraphic = m_IGraphics.AddCurveSpline(daxStart[0], dayStart[0], 0.0);
  822.                                 m_IVertices = null;
  823.                                 m_IVertices = m_ITheGraphic.getVertices();
  824.  
  825.                                 varX.putDouble(daX[0]);
  826.                                 varY.putDouble(daY[0]);
  827.                                 varZ.putDouble(0.0);
  828.  
  829.                                 m_ITheVertex = null;
  830.                                 m_ITheVertex = m_IVertices.Add(varX, varY, varZ, nParam, nParam, nParam, nParam, nParam, nParam, nParam, nParam);
  831.  
  832.                                 prevX = xStart; prevY = yStart;  // set previous point for spline
  833.                                 pprevX = xStart; pprevY = yStart;  // set previous point for spline
  834.                                 currX = x; currY = y;
  835.                                 ClipIt = true;
  836.  
  837.                                 //byte b = 1;
  838.                                 //m_ITheView.putUpdate(b);  // delay update until we tell it to
  839.                                 repaint();
  840.                                 splineStarted = true;
  841.                             }
  842.                             else
  843.                             {
  844.                                 byte b = 0;
  845.                                 m_ITheView.putUpdate(b);  // delay update until we tell it to
  846.  
  847.                                 varX.putDouble(daX[0]);
  848.                                 varY.putDouble(daY[0]);
  849.                                 varZ.putDouble(0.0);
  850.  
  851.                                 m_ITheVertex = null;
  852.                                 m_ITheVertex = m_IVertices.Add(varX, varY, varZ, nParam, nParam, nParam, nParam, nParam, nParam, nParam, nParam);
  853.  
  854.                                 b = 0;
  855.                                 m_ITheView.putUpdate(b);  // delay update until we tell it to
  856.  
  857.                                 Zoom = false;
  858.  
  859.                                 pprevX = prevX; pprevY = prevY;  // set previous point for spline 1st set of point
  860.                                 prevX = currX; prevY = currY;  // set previous point for spline, second set of points
  861.                                 currX = x; currY = y;  // third set of points to form clipping rect
  862.                                 ClipIt = true;
  863.  
  864.                                 repaint();
  865.                                 splineStarted = true;
  866.  
  867.                             }
  868.  
  869.                         }
  870.                         catch (Exception e)
  871.                         {
  872.                             Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  873.                         }
  874.                         draggingStarted = false;
  875.                         break;
  876.  
  877.                     case Parent.STARCLICK:
  878.                         try  // always use the try/catch to catch any returned errors from OLE/SDK
  879.                         {
  880.                         }
  881.                         catch (Exception e)
  882.                         {
  883.                             Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)");
  884.                         }
  885.                         draggingStarted = false;
  886.                         break;
  887.  
  888.                 }
  889.                 Zoom = false;
  890.  
  891.             }
  892.  
  893.         }
  894.         return true;
  895.     }
  896.  
  897.     public boolean mouseDown(Event  evt, int  x, int  y)
  898.     {
  899.         //  mouse buton released. If dragging was started the assume this is finish of drag.
  900.         draggingStarted = false;
  901.         xStart = x;
  902.         yStart = y;
  903.  
  904.         if (evt.modifiers == Event.META_MASK)
  905.         {
  906.             (new ViewSourceDialog(Parent.frame, false, helpStrings.General)).show();
  907.             return true;
  908.         }
  909.         else
  910.         {
  911.             if (whichButtonDown == Parent.PICKCLICK && m_ITheView != null && m_ITheDrawing != null)
  912.             {
  913.                 double dxStart, dyStart;
  914.                 double[] daX = new double[1], daY = new double[1], daxStart = new double[1], dayStart = new double[1];
  915.  
  916.                 try  // always use the try/catch to catch any returned errors from OLE/SDK
  917.                 {
  918.                     m_ITheView.ScreenToView(xStart, yStart, daxStart, dayStart); // pass in a double and get double array returned
  919.  
  920.                     com.ms.com.Variant nParam = new com.ms.com.Variant();
  921.                     // Set the Variant for no parameter
  922.                     nParam.noParam();
  923.  
  924.                     com.ms.com.Variant dParam = new com.ms.com.Variant();
  925.                     dParam.putDouble(0.1);  // set the proximity to graphic that you must click to select a graphic
  926.  
  927.                     //dxStart = xStart; dyStart = yStart;
  928.                     // METHOD: public abstract imsigx40.PickResult PickPoint(double, double, com.ms.com.Variant, com.ms.com.Variant, com.ms.com.Variant, com.ms.com.Variant, com.ms.com.Variant, com.ms.com.Variant, com.ms.com.Variant);                            
  929.                     imsigx40.PickResult m_IThePickedResults =
  930.                         (imsigx40.PickResult) m_ITheView.PickPoint(daxStart[0], dayStart[0], dParam, nParam, nParam, nParam, nParam, nParam, nParam);
  931.  
  932.                     imsigx40.IGraphic m_IPickGraphic=null;
  933.  
  934.                     int pickCount = m_IThePickedResults.getCount();  // with PickPoint you will not get more than count of one
  935.  
  936.                     if (pickCount > 0)
  937.                     {
  938.                         imsigx40.Properties pProp;
  939.                         // First deselect the current selected graphic if any. If we were to Shift Click the object and
  940.                         // test for that here we could do multiple select. We would have to keep a list of the selected
  941.                         // objects for deselection.
  942.                         if (m_ISelectedGraphic != null)
  943.                         {
  944.                             m_IPickGraphic = m_ISelectedGraphic;
  945.                             //m_IPickGraphic.Unselect();
  946.                             // METHOD: public abstract imsigx40.Properties getProperties();
  947.                             pProp = (imsigx40.Properties) m_IPickGraphic.getProperties();            
  948.  
  949.                             // METHOD: public abstract imsigx40.Property getItem(com.ms.com.Variant);
  950.                             com.ms.com.Variant sVar = new com.ms.com.Variant();
  951.                               sVar.putString("PenColor");  // insert string into variant to get the PenColor property
  952.  
  953.                             imsigx40.Property m_IThePenColor = (imsigx40.Property) pProp.getItem(sVar);
  954.  
  955.                             // METHOD: public abstract void putValue(int, com.ms.com.Variant);
  956.                             com.ms.com.Variant iVar = new com.ms.com.Variant();
  957.                         
  958.                             iVar.putInt(savedColor);
  959.                             m_IThePenColor.putValue(0, iVar);
  960.  
  961.                             //m_ISelectedGraphic.VariantClear();
  962.                             m_ISelectedGraphic = null;
  963.                             m_IThePenColor = null;
  964.                             m_IPickGraphic = null;
  965.                             m_IThePenColor = null;
  966.                             pProp = null;
  967.  
  968.                         }
  969.  
  970.                         for (int ii=0; ii < pickCount; ii++)
  971.                         {
  972.                             com.ms.com.Variant iVar = new com.ms.com.Variant();
  973.                             iVar.putInt(ii);
  974.                             // METHOD: public abstract imsigx40.PickEntry getItem(com.ms.com.Variant);
  975.                             imsigx40.PickEntry m_ITheItem = m_IThePickedResults.getItem(iVar);
  976.                             m_IPickGraphic = m_ITheItem.getGraphic();
  977.  
  978.                         
  979.                             pProp = m_IPickGraphic.getProperties();            
  980.  
  981.                             com.ms.com.Variant sVar = new com.ms.com.Variant();
  982.                             sVar.putString("PenColor");
  983.  
  984.                             // METHOD: public abstract imsigx40.Property getItem(com.ms.com.Variant);
  985.                             imsigx40.Property m_IThePenColor = (imsigx40.Property) pProp.getItem(sVar);
  986.  
  987.                             savedColor = (m_IThePenColor.getValue(0)).getInt();
  988.  
  989.                             // METHOD: public abstract void putValue(int, com.ms.com.Variant);
  990.                             com.ms.com.Variant dVar = new com.ms.com.Variant();
  991.                             dVar.putInt(0xFF00FF);  // use Magenta as selected color
  992.  
  993.                             //m_IPickGraphic.Select();
  994.                             m_IThePenColor.putValue(0, dVar);
  995.                         
  996.                             m_ISelectedGraphic = null;
  997.  
  998.                             m_ISelectedGraphic = m_IPickGraphic;  // save to global for unpick
  999.  
  1000.                             m_ITheItem = null;
  1001.  
  1002.                             m_IThePenColor = null;
  1003.  
  1004.                             m_IPickGraphic = null;
  1005.                             pProp = null;
  1006.  
  1007.                         }
  1008.             
  1009.                     }
  1010.                 
  1011.                     byte b = 1;
  1012.                     m_ITheView.putUpdate(b);  // delay update until we tell it to
  1013.                     m_IGraphics = null;
  1014.                 }
  1015.                 // this is how we handle an HRESULT of E_FAIL (defined in winerror.h for C++)
  1016.                 catch (com.ms.com.ComFailException e)
  1017.                 {
  1018.                     // don't do anything, we just missed selecting a point.
  1019.                 }
  1020.                 // this is how we handle an HRESULT of a system error (defined in winerror.h for C++)
  1021.                 catch (com.ms.com.ComException e)
  1022.                 {
  1023.                     Parent.StatusBox.setText("Error in OLE transaction (IMSIGX40)" + e.toString());
  1024.                 }
  1025.                 draggingStarted = false;
  1026.             }
  1027.         }
  1028.         return true;
  1029.     }
  1030.  
  1031.  
  1032.     public void reshape(int x, int y, int width, int height)
  1033.     {
  1034.         // Java 1.0 doesn't have a resize event when the screen is resized so we must use
  1035.         // the resize method which is called from layout(). Here we can make sure that
  1036.         // the screen isn't painted SDK code isn't called twice
  1037.         fromNew = false;  // not a new drawing
  1038.         Zoom = true;
  1039.         super.reshape(x, y, width, height);
  1040.  
  1041.     }
  1042.  
  1043.     public boolean handleEvent(Event event)
  1044.     {
  1045.         return super.handleEvent(event);
  1046.     }
  1047.  
  1048.     // bypass the regular update which clears the screen, let us do that in paint
  1049.     public void update(java.awt.Graphics g)
  1050.     {   paint(g);
  1051.     }
  1052.  
  1053.     /** this is the paint method, here we set up for SDK drawing and call the SDK's refresh() **/
  1054.     public void paint(java.awt.Graphics g)
  1055.     {
  1056.  
  1057.         if (m_ITheView != null) // make sure we have a view open (also implies and open app, drawing ..
  1058.         {
  1059.             byte b; // used for passing true/false as variant
  1060.             // screen is cleared by method update() first
  1061.             Rectangle rec = bounds();  // get full rectangle of graphics context
  1062.  
  1063.             rec.x = 0; rec.y = 0;
  1064.             g.setColor(Color.white);
  1065.             if (ClipIt == false)
  1066.                 g.clearRect(0, 0, rec.width, rec.height);
  1067.  
  1068.             //g.fillRect(0, 0, width, height);
  1069.             g.setColor(getForeground());
  1070.  
  1071.             // always use the try/catch to catch any returned errors from OLE/SDK
  1072.             try
  1073.             {
  1074.                 // allow clipping of small region. This make refresh redraw only clipped region
  1075.                 // which ha less flicker than full screen redraw
  1076.                 if (ClipIt == true)
  1077.                 {   int x, y, width, height;
  1078.                     double x1 = Math.min(Math.min(currX, prevX), pprevX) - 10;
  1079.                     double x2 = Math.max(Math.max(currX, prevX), pprevX) + 10;
  1080.  
  1081.                     if ((int)x1 < 0) x1 = 0;
  1082.                     if ((int)x2 > bounds().width) x2 = bounds().width;
  1083.                     x = (int) x1;
  1084.                     width = (int)(x2 - x1);
  1085.  
  1086.                     double y1 = Math.min(Math.min(currY, prevY), pprevY) - 10;
  1087.                     double y2 = Math.max(Math.max(currY, prevY), pprevY) + 10;
  1088.                     if ((int)y1 < 0) y1 = 0;
  1089.                     if ((int)y2 > bounds().height) y2 = bounds().height;
  1090.  
  1091.                     height = (int)(y2 - y1);
  1092.                     y = (int) y1;
  1093.  
  1094.                     g.clearRect(x, y, width, height);
  1095.                     g.clipRect(x, y, width, height);
  1096.                 }
  1097.                 ClipIt = false;  // don't allow clipping of a region
  1098.  
  1099.  
  1100.                 int CompHwnd = 0;
  1101.                 // get the Windows handle for the canvas so that IMSI's SDK can draw direct to the window
  1102.                 ComponentPeer p = this.getPeer();
  1103.                 if( p != null )
  1104.                 {
  1105.                      com.ms.awt.peer.ComponentPeerX peer1 = (com.ms.awt.peer.ComponentPeerX)p;
  1106.                      CompHwnd = peer1.gethwnd();  // Microsoft specific method
  1107.                 }
  1108.  
  1109.                 b = 0;
  1110.                 m_ITheView.putUpdate(b);  // delay update until we tell it to
  1111.                 m_ITheView.putHWND(CompHwnd);
  1112.                 m_ITheView.putMappingMode(1);
  1113.  
  1114.                 /* we don't want margins as this will redraw with margins.
  1115.                    Using the same screen coordinates this will shrink the screen
  1116.                    by margin each redraw.        
  1117.                 */
  1118.                 b = 0;
  1119.                 m_ITheView.putMargins(b);
  1120.  
  1121.                 b = 1;  // set to same aspect ratio
  1122.                 m_ITheView.putFixedAspectRatio (b);
  1123.  
  1124.                 boolean viewChanged = ((viewWidth == 0.0) && (viewHeight == 0.0));
  1125.                 if (viewChanged)
  1126.                 {
  1127.                     // Initial settings
  1128.                     m_ITheView.putScreenLeft(0.0);
  1129.                     m_ITheView.putScreenTop(0.0);
  1130.                     m_ITheView.putScreenWidth(rec.width);
  1131.                     m_ITheView.putScreenHeight(rec.height);
  1132.                     m_ITheView.ZoomToExtents();
  1133.                    // m_ITheView.Refresh(); // just call the SDK's Refresh method.
  1134.                 }
  1135.                 else
  1136.                 {
  1137.                     // Saved settings
  1138.                     m_ITheView.Refresh(); // just call the SDK's Refresh method.
  1139.                 }
  1140.  
  1141.                 //if ViewChanged then UpdateScrollParams;
  1142.  
  1143.                 // screen dimensions
  1144.                 screenLeft = m_ITheView.getScreenLeft();
  1145.                 screenTop = m_ITheView.getScreenTop();
  1146.                 screenWidth = m_ITheView.getScreenWidth();
  1147.                 screenHeight = m_ITheView.getScreenHeight();        
  1148.  
  1149.                 // drawing/view dimensions
  1150.                 viewLeft = m_ITheView.getViewLeft();
  1151.                 viewTop = m_ITheView.getViewTop();
  1152.                 viewWidth = m_ITheView.getViewWidth();
  1153.                 viewHeight = m_ITheView.getViewHeight();        
  1154.                 Parent.StatusBox.setText("rectangle: " + screenLeft + "  " + screenTop + "  " + screenWidth + "  " + screenHeight + " *** " + viewLeft + "  " + viewTop + "  " + viewWidth + "  " + viewHeight);
  1155.             }
  1156.             catch (com.ms.com.ComException e)
  1157.             {   Parent.StatusBox.setText("Error connecting to IMSIGX40 OLE");
  1158.             }
  1159.         }
  1160.     }
  1161.  
  1162. }
  1163.  
  1164.